#include <stdio.h>

#include "Cache.h"

int main() {
    // 创建缓存，最大缓存大小为 3
    Cache *cache = create_cache(3);

    // 添加文件到缓存
    const char *key1 = "index.html";
    const char *content1 = "<html>...</html>";
    add_to_cache(cache, key1, content1, strlen(content1) + 1);

    const char *key2 = "about.html";
    const char *content2 = "<html>About Us</html>";
    add_to_cache(cache, key2, content2, strlen(content2) + 1);

    const char *key3 = "contact.html";
    const char *content3 = "<html>Contact Us</html>";
    add_to_cache(cache, key3, content3, strlen(content3) + 1);

    add_to_cache(cache, key3, content3, strlen(content3) + 1);
    add_to_cache(cache, key3, content3, strlen(content3) + 1);

    // 获取并打印缓存中的文件内容
    char *retrieved_content = (char *)get_from_cache(cache, key1);
    if (retrieved_content) {
        printf("File: %s, Content: %s\n", key1, retrieved_content);
    }

    // 添加一个新的文件，导致最久未使用的文件被淘汰
    const char *key4 = "services.html";
    const char *content4 = "<html>Services</html>";
    add_to_cache(cache, key4, content4, strlen(content4) + 1);

    // 尝试获取被淘汰的文件
    // char *retrieve_content = (char *)get_from_cache(cache, key1);
    // if (retrieve_content) {
    //     printf("File: %s, Content: %s\n", key2, retrieve_content);
    // } else {
    //     printf("File %s not found (LRU evicted)\n", key2);
    // }

    // 销毁缓存
    destroy_cache(cache);

    return 0;
}
